/**
 * 安装 @babel/plugin-syntax-dynamic-import 开发依赖
 * @description 路由懒加载
 */
// import Login from '@/views/Login.vue'
const Login = () => import (/* webpackChunkName: "login_welcome" */'@/views/Login.vue');
// import Welcome from '@/views/Welcome.vue'
const Welcome = () => import (/* webpackChunkName: "login_welcome" */'@/views/Welcome.vue');
// import Home from '@/views/Home.vue'
const Home = () => import (/* webpackChunkName: "login_welcome" */'@/views/Home.vue');

// import Users from '@/views/User/Users.vue'
const Users = () => import (/* webpackChunkName: "users_Rights_Roles" */'@/views/User/Users.vue');
// import Rights from '@/views/power/Rights.vue'
const Rights = () => import (/* webpackChunkName: "users_Rights_Roles" */'@/views/power/Rights.vue');
// import Roles from '@/views/power/Roles.vue'
const Roles = () => import (/* webpackChunkName: "users_Rights_Roles" */'@/views/power/Roles.vue');


// import Cate from '@/views/goods/Cate.vue'
const Cate = () => import (/* webpackChunkName: "Cate_params" */'@/views/goods/Cate.vue');
// import Params from '@/views/goods/Params.vue'
const Params = () => import (/* webpackChunkName: "Cate_params" */'@/views/goods/Params.vue');


// import AddGoods from '@/views/goods/list/Add.vue'
const AddGoods = () => import (/* webpackChunkName: "goodsList" */'@/views/goods/list/Add.vue');
// import EditGoods from '@/views/goods/list/Edit.vue'
const EditGoods = () => import (/* webpackChunkName: "goodsList" */'@/views/goods/list/Edit.vue');
// import List from "@/views/goods/list/List.vue"
const List = () => import (/* webpackChunkName: "goodsList" */'@/views/goods/list/List.vue');


// import Order from '@/views/goods/order/Order.vue'
const Order = () => import (/* webpackChunkName: "Order_Report" */'@/views/goods/order/Order.vue');
// import EditOrder from '@/views/goods/order/EditOrder.vue'
const EditOrder = () => import (/* webpackChunkName: "Order_Report" */'@/views/goods/order/EditOrder.vue');
// import Report from '@/views/report/Report.vue'
const Report = () => import (/* webpackChunkName: "Order_Report" */'@/views/report/Report.vue');

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
	// 登录
	{ path: "/login", component: Login },
	// 重定向
	{ path: "/", redirect: "/home" },
	// home页
	{
		path: "/home", redirect: '/index', component: Home, children: [
			// 欢迎页
			{ path: "/index", name: "index", component: Welcome },
			// 用户列表
			{ path: "/users", name: "users", component: Users },
			// 权限列表
			{ path: "/rights", name: "rights", component: Rights, },
			// 角色列表
			{ path: "/roles", name: 'roles', component: Roles },
			// 商品分类
			{ path: "/categories", name: "categories", component: Cate },
			// 商品参数
			{ path: "/params", name: "params", component: Params },
			// 商品列表
			{ path: '/goods', name: "goods", component: List, },
			// 添加商品
			{ path: '/goods/add', name: "goodsAdd",component: AddGoods },
			// 编辑商品
			{ path: '/goods/edit/:id', name: 'goodsEdit', component:EditGoods},
			// 订单列表
			{ path:"/orders", name:"order", component: Order },
			// 编辑订单
			{ path:"/orders/edit/:id",name:"editOrder",component:EditOrder },
			// 数据报表
			{ path:"/reports", name:"report",component: Report }
		]
	}
]

const router = new VueRouter({
	routes,
	mode: 'history',
})

router.beforeEach((to, from, next) => {
	// to 将要访问的路径；from 从哪个路径跳转而来；next()放行next('/login')
	// 获取token
	const token = window.sessionStorage.getItem('token');
	if (to.path == '/login') {
		next();
	}
	if (!token && to.path !== '/login') {
		console.log(222);
		next('/login')
	}
	next();
})

export default router
